
import React, { Component }  from 'react';
import {
    View,
    Text,
    TextInput,
    StyleSheet
} from 'react-native';
const Dimensions = require('Dimensions');
const { width } = Dimensions.get('window');
import {setSpText,setHW} from '../../../component/ScreenUtil'
import { getCoursePartById, letParentEnroll, listParents ,insertReply,insertComment} from '../../../api/my';
export default class ReplayComp extends Component {
    constructor(props) {
        super(props);
        this.state={
            inputText:''
        }
    }
    render() {
        return (
            <View style={[styles.inputBox, styles.inputViewWrapper]}>
                <TextInput style={styles.input} 
                    autoFocus={true}
                    onChangeText={(text) => this.setState({ inputText: text })}
                    value={this.state.inputText}
                    onBlur={()=>this.onBlurFun()}
                    underlineColorAndroid='transparent' 
                    placeholder={'说点什么吧'} />
                <Text style={[this.state.inputText?styles.sendBtnActive:styles.sendBtn]} 
                        onPress={()=>this.sendText()}>发送
                </Text>
            </View>
        )
    }
    // 失去焦点时 去掉回复组件
    onBlurFun(){
        this.props.updateShowInput(false)
    }
    // 点击发送回复评论时
    sendText(){
        let emp= this.state.inputText.split(" ").join("").length === 0//全是空格
        if(emp){
            Toast.message("请输入内容")
        }else{
            let json={
                "USER_ID": global.ECourseConstant.userInfo.uuid,//用户id
                "COMMENT_ID": this.props.CommentId,//评论id
                "REPLY_CONTENT": this.state.inputText
            }
            insertReply(json).then(res=>{
                this.setState({ inputText: '' })//成功后清空
                this.props.TabFun();//调用父组件的TabFun方法
                this.onBlurFun();
            })
        }
    }
}
const styles = StyleSheet.create({
    // 回复
    inputViewWrapper: {
        position: 'absolute',
        width: '100%',
        bottom: 0
    },
    inputBox: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        backgroundColor: '#fff',
        paddingTop: setHW(6),
        paddingRight:1,
        paddingBottom: setHW(6),
        width: width,
        height: setHW(90),
    },
    input: {
        height: setHW(76),
        backgroundColor: '#F5F5F5',
        textAlign: 'left',
        paddingLeft: setHW(12),
        paddingRight: setHW(6),
        width: width - setHW(130),
    },
    sendBtn:{
        height:setHW(76),
        width:setHW(120),
        fontSize:setSpText(28),
        paddingTop:setHW(20),
        color:'#ccc',
        borderWidth:1,
        borderColor:'#F5F5F5',
        justifyContent:'center',
        alignItems:'center',
        textAlign:'center'
    },
    sendBtnActive:{
        height:setHW(76),
        width:setHW(120),
        fontSize:setSpText(28),
        paddingTop:setHW(20),
        color:'#fff',
        backgroundColor:'#FF8A00',
        borderWidth:1,
        borderColor:'#FF8A00',
        justifyContent:'center',
        alignItems:'center',
        textAlign:'center',
        borderRadius:setHW(8),
    }
});
